package com.example.springstack.mybatisplus.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;


/**
 * @author qiangfanghao
 * @date
 * 用户表
 * mybatis+hibernate实体类自动创建表
 * @Entity: 用于实体类的创建
 * @TableName: mybatis注解用于表的查询
 */

@Data
@Entity
@TableName("User")
public class User implements  Serializable {

    @Id
    @GenericGenerator(name = "HibAssigned", strategy = "native")
    @GeneratedValue(generator = "HibAssigned")
    @TableId(type = IdType.AUTO)
    @Column(name = "id", length = 20, nullable = false, unique = true)
    private Long id;

    /** 用户登录账号 */
    @Column(name = "username", length = 64, nullable = false)
    private String username;

    /** 用户登录密码
     * 序列化json时忽略该字段返回: @JsonIgnore
     * */
    @JsonIgnore
    @Column(name = "password", columnDefinition = "varchar(64)")
    private String password;

    /** 昵称 */
    @Column(name = "nickname", nullable = false,columnDefinition = "varchar(64)")
    private String nickname;

    /** 是否可用 */
    @Column(name = "enable",nullable = false,columnDefinition = "tinyint(1)")
    private Boolean enable;

    /** 是否被锁定 */
    @Column(name = "locked",nullable = false,columnDefinition = "tinyint(1)")
    private Boolean locked;

    /** 角色更新时间 */
    @Column(name = "updateTime",length = 20,nullable = false)
    private Long updateTime;


    /** 用户权限
     *  hibernate: @Transient 不需要持久化到数据库,生成表数据时忽略该字段
     *  mybatis: @TableField(exist = false) 不是数据库字段,查询时忽略
     * */
    @Transient
    @TableField(exist = false)
    private List<String> authorities;

    public User() {
    }

    public User(String username, String password, String nickname, Boolean enable, Boolean locked, Long updateTime) {
        this.username = username;
        this.password = password;
        this.nickname = nickname;
        this.enable = enable;
        this.locked = locked;
        this.updateTime = updateTime;
    }
}
